package com.xingchi.tornado.security.handler;

import com.xingchi.tornado.security.model.IUser;
import com.xingchi.tornado.security.model.LoginData;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.session.FindByIndexNameSessionRepository;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
 * 主体名称session填充
 *
 * @author xingchi
 * @date 2025/9/17 22:42
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class PrincipalNameSessionAttributeService implements SessionAttributeService {

    @Override
    public void fillSessionAttribute(HttpSession session, LoginData<? extends IUser> loginData) {
        session.setAttribute(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, String.valueOf(loginData.getUserId()));
    }

}
